/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.collection.CollUtil
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.Node
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.Button
 *  javafx.scene.control.CheckBox
 *  javafx.scene.control.ScrollPane
 *  javafx.scene.control.TableCell
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.scene.layout.VBox
 *  javafx.stage.Stage
 *  javafx.util.Callback
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.util.CollectionUtils
 */
package com.gys.controller.accept;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.AcceptUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.CacheUtil;
import com.gys.common.util.ConstUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.accept.AcceptController;
import com.gys.controller.index.IndexController;
import com.gys.data.accept.AcceptInData;
import com.gys.data.accept.DiaoboOutData;
import com.gys.data.deviceCheck.GsdcStatus;
import com.gys.data.example.GetLoginStoreOutData;
import com.gys.view.accept.AddView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

@FXMLController
public class AddAcceptController
extends BaseController
implements Initializable {
    private final int pageSize = ConstUtil.DEFAULT_PAGESIZE;
    private final int defaultPageCount = ConstUtil.DEFAULT_PAGECOUNT;
    private ObservableList<DiaoboOutData> observableTableList = FXCollections.observableArrayList(new ArrayList());
    @FXML
    private AnchorPane anchorPane;
    @FXML
    private ScrollPane scrollPane;
    @FXML
    private VBox vBox;
    @FXML
    private Button enterBtn;
    @FXML
    private TableView<DiaoboOutData> tableView;
    @FXML
    private TableColumn<DiaoboOutData, CheckBox> checkBox;
    @FXML
    private TableColumn<DiaoboOutData, String> wmPsdh;
    @FXML
    private TableColumn<DiaoboOutData, String> wmCjrq;
    @FXML
    private TableColumn<DiaoboOutData, String> totalAmount;
    @FXML
    private TableColumn<DiaoboOutData, String> totalQty;
    @FXML
    private TableColumn<DiaoboOutData, String> type;
    @Autowired
    private AcceptController acceptController;
    @Autowired
    private IndexController indexController;
    private Timer timer = new Timer();

    public void initialize(URL location, ResourceBundle resources) {
        this.scrollPane.setPrefWidth(this.getContentWidth());
        this.scrollPane.setPrefHeight(this.getContentHeight());
        this.vBox.setPrefWidth(this.getContentWidth());
        this.vBox.setPrefHeight(this.getContentHeight());
        this.tableView.setPrefWidth(this.getContentWidth());
        this.init();
    }

    @Override
    public void init() {
        this.timer.schedule(new TimerTask(){

            @Override
            public void run() {
                AddView view = SpringUtil.getBean(AddView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent event) {
                        if (event.getCode() == KeyCode.ENTER) {
                            AddAcceptController.this.saveAdd();
                            return;
                        }
                        if (event.getCode() == KeyCode.ESCAPE) {
                            AddAcceptController.this.closeWindows();
                            return;
                        }
                    }
                });
            }
        }, 1000L);
        this.initTable();
    }

    @FXML
    private void saveAdd() {
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        List<Integer> indexList = this.getSelectIndex();
        if (ObjectUtil.isEmpty(indexList)) {
            alert.setContentText("\u8bf7\u9009\u62e9\u8bb0\u5f55");
            alert.showAndWait();
            return;
        }
        String psdh = "";
        for (Integer index : indexList) {
            psdh = ((DiaoboOutData)this.observableTableList.get(index - 1)).getWmPsdh();
        }
        AcceptInData inData = new AcceptInData();
        inData.setGsahPsVoucherId(psdh);
        inData.setGsahBrId(((GetLoginStoreOutData)CacheUtil.get("store")).getStoCode());
        HttpJson rsp = AcceptUtil.save(inData);
        if (rsp.isSuccess()) {
            this.acceptController.initTable(0, psdh);
            this.init();
            this.anchorPane.getScene().getWindow().hide();
        } else {
            alert.showAndWait();
        }
    }

    @FXML
    private void closeWindows() {
        this.init();
        this.anchorPane.getScene().getWindow().hide();
    }

    public TableView<DiaoboOutData> initTable() {
        AcceptInData inData = new AcceptInData();
        HttpJson rsp = AcceptUtil.diaoboList(inData);
        if (!rsp.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", rsp.getMsg());
            alert.showAndWait();
            return new TableView();
        }
        List<DiaoboOutData> list = JSON.parseArray((String)rsp.getMsg(), DiaoboOutData.class);
        int i = 0;
        for (DiaoboOutData outData : list) {
            outData.setType("\u914d\u9001\u5355");
            outData.setIndex(i + 1);
            ++i;
        }
        this.observableTableList.clear();
        this.observableTableList = FXCollections.observableArrayList((Collection)list);
        this.bingTableCell();
        this.tableView.setItems(this.observableTableList);
        return this.tableView;
    }

    private void bingTableCell() {
        this.checkBox.setCellValueFactory(cellData -> ((DiaoboOutData)cellData.getValue()).getCheckBox().getCustomCheckBox());
        this.checkBox.setCellFactory(col -> {
            TableCell<DiaoboOutData, CheckBox> cell = new TableCell<DiaoboOutData, CheckBox>(){

                protected void updateItem(CheckBox item, boolean empty) {
                    super.updateItem(item, empty);
                    this.setGraphic((Node)item);
                    if (item != null) {
                        item.setOnMouseClicked(col -> {
                            if (CollUtil.isEmpty((Collection)AddAcceptController.this.observableTableList)) {
                                return;
                            }
                            int index = this.getIndex();
                            for (int i = 0; i < AddAcceptController.this.observableTableList.size(); ++i) {
                                if (i == index) continue;
                                ((DiaoboOutData)AddAcceptController.this.observableTableList.get(i)).getCheckBox().setSelectStatus(false);
                            }
                        });
                    }
                }
            };
            return cell;
        });
        this.wmPsdh.setCellValueFactory((Callback)new PropertyValueFactory(this.wmPsdh.getId()));
        this.wmCjrq.setCellValueFactory((Callback)new PropertyValueFactory(this.wmCjrq.getId()));
        this.totalAmount.setCellValueFactory((Callback)new PropertyValueFactory(this.totalAmount.getId()));
        this.totalQty.setCellValueFactory((Callback)new PropertyValueFactory(this.totalQty.getId()));
        this.type.setCellValueFactory((Callback)new PropertyValueFactory(this.type.getId()));
    }

    private List<GsdcStatus> getAllStatus() {
        ArrayList<GsdcStatus> list = new ArrayList<GsdcStatus>();
        list.add(new GsdcStatus("1", "\u5df2\u5ba1\u6838"));
        list.add(new GsdcStatus("0", "\u672a\u5ba1\u6838"));
        return list;
    }

    private List<Integer> getSelectIndex() {
        ArrayList<Integer> ids = new ArrayList<Integer>();
        if (!CollectionUtils.isEmpty(this.observableTableList)) {
            for (DiaoboOutData i : this.observableTableList) {
                if (!i.getCheckBox().isSelected().booleanValue()) continue;
                ids.add(i.getIndex());
            }
        }
        return ids;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public int getDefaultPageCount() {
        return this.defaultPageCount;
    }

    public ObservableList<DiaoboOutData> getObservableTableList() {
        return this.observableTableList;
    }

    public AnchorPane getAnchorPane() {
        return this.anchorPane;
    }

    public ScrollPane getScrollPane() {
        return this.scrollPane;
    }

    public VBox getVBox() {
        return this.vBox;
    }

    public Button getEnterBtn() {
        return this.enterBtn;
    }

    public TableView<DiaoboOutData> getTableView() {
        return this.tableView;
    }

    public TableColumn<DiaoboOutData, CheckBox> getCheckBox() {
        return this.checkBox;
    }

    public TableColumn<DiaoboOutData, String> getWmPsdh() {
        return this.wmPsdh;
    }

    public TableColumn<DiaoboOutData, String> getWmCjrq() {
        return this.wmCjrq;
    }

    public TableColumn<DiaoboOutData, String> getTotalAmount() {
        return this.totalAmount;
    }

    public TableColumn<DiaoboOutData, String> getTotalQty() {
        return this.totalQty;
    }

    public TableColumn<DiaoboOutData, String> getType() {
        return this.type;
    }

    public AcceptController getAcceptController() {
        return this.acceptController;
    }

    public IndexController getIndexController() {
        return this.indexController;
    }

    public Timer getTimer() {
        return this.timer;
    }

    public void setObservableTableList(ObservableList<DiaoboOutData> observableTableList) {
        this.observableTableList = observableTableList;
    }

    public void setAnchorPane(AnchorPane anchorPane) {
        this.anchorPane = anchorPane;
    }

    public void setScrollPane(ScrollPane scrollPane) {
        this.scrollPane = scrollPane;
    }

    public void setVBox(VBox vBox) {
        this.vBox = vBox;
    }

    public void setEnterBtn(Button enterBtn) {
        this.enterBtn = enterBtn;
    }

    public void setTableView(TableView<DiaoboOutData> tableView) {
        this.tableView = tableView;
    }

    public void setCheckBox(TableColumn<DiaoboOutData, CheckBox> checkBox) {
        this.checkBox = checkBox;
    }

    public void setWmPsdh(TableColumn<DiaoboOutData, String> wmPsdh) {
        this.wmPsdh = wmPsdh;
    }

    public void setWmCjrq(TableColumn<DiaoboOutData, String> wmCjrq) {
        this.wmCjrq = wmCjrq;
    }

    public void setTotalAmount(TableColumn<DiaoboOutData, String> totalAmount) {
        this.totalAmount = totalAmount;
    }

    public void setTotalQty(TableColumn<DiaoboOutData, String> totalQty) {
        this.totalQty = totalQty;
    }

    public void setType(TableColumn<DiaoboOutData, String> type) {
        this.type = type;
    }

    public void setAcceptController(AcceptController acceptController) {
        this.acceptController = acceptController;
    }

    public void setIndexController(IndexController indexController) {
        this.indexController = indexController;
    }

    public void setTimer(Timer timer) {
        this.timer = timer;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AddAcceptController)) {
            return false;
        }
        AddAcceptController other = (AddAcceptController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        if (this.getPageSize() != other.getPageSize()) {
            return false;
        }
        if (this.getDefaultPageCount() != other.getDefaultPageCount()) {
            return false;
        }
        ObservableList<DiaoboOutData> this$observableTableList = this.getObservableTableList();
        ObservableList<DiaoboOutData> other$observableTableList = other.getObservableTableList();
        if (this$observableTableList == null ? other$observableTableList != null : !this$observableTableList.equals(other$observableTableList)) {
            return false;
        }
        AnchorPane this$anchorPane = this.getAnchorPane();
        AnchorPane other$anchorPane = other.getAnchorPane();
        if (this$anchorPane == null ? other$anchorPane != null : !this$anchorPane.equals(other$anchorPane)) {
            return false;
        }
        ScrollPane this$scrollPane = this.getScrollPane();
        ScrollPane other$scrollPane = other.getScrollPane();
        if (this$scrollPane == null ? other$scrollPane != null : !this$scrollPane.equals(other$scrollPane)) {
            return false;
        }
        VBox this$vBox = this.getVBox();
        VBox other$vBox = other.getVBox();
        if (this$vBox == null ? other$vBox != null : !this$vBox.equals(other$vBox)) {
            return false;
        }
        Button this$enterBtn = this.getEnterBtn();
        Button other$enterBtn = other.getEnterBtn();
        if (this$enterBtn == null ? other$enterBtn != null : !this$enterBtn.equals(other$enterBtn)) {
            return false;
        }
        TableView<DiaoboOutData> this$tableView = this.getTableView();
        TableView<DiaoboOutData> other$tableView = other.getTableView();
        if (this$tableView == null ? other$tableView != null : !this$tableView.equals(other$tableView)) {
            return false;
        }
        TableColumn<DiaoboOutData, CheckBox> this$checkBox = this.getCheckBox();
        TableColumn<DiaoboOutData, CheckBox> other$checkBox = other.getCheckBox();
        if (this$checkBox == null ? other$checkBox != null : !this$checkBox.equals(other$checkBox)) {
            return false;
        }
        TableColumn<DiaoboOutData, String> this$wmPsdh = this.getWmPsdh();
        TableColumn<DiaoboOutData, String> other$wmPsdh = other.getWmPsdh();
        if (this$wmPsdh == null ? other$wmPsdh != null : !this$wmPsdh.equals(other$wmPsdh)) {
            return false;
        }
        TableColumn<DiaoboOutData, String> this$wmCjrq = this.getWmCjrq();
        TableColumn<DiaoboOutData, String> other$wmCjrq = other.getWmCjrq();
        if (this$wmCjrq == null ? other$wmCjrq != null : !this$wmCjrq.equals(other$wmCjrq)) {
            return false;
        }
        TableColumn<DiaoboOutData, String> this$totalAmount = this.getTotalAmount();
        TableColumn<DiaoboOutData, String> other$totalAmount = other.getTotalAmount();
        if (this$totalAmount == null ? other$totalAmount != null : !this$totalAmount.equals(other$totalAmount)) {
            return false;
        }
        TableColumn<DiaoboOutData, String> this$totalQty = this.getTotalQty();
        TableColumn<DiaoboOutData, String> other$totalQty = other.getTotalQty();
        if (this$totalQty == null ? other$totalQty != null : !this$totalQty.equals(other$totalQty)) {
            return false;
        }
        TableColumn<DiaoboOutData, String> this$type = this.getType();
        TableColumn<DiaoboOutData, String> other$type = other.getType();
        if (this$type == null ? other$type != null : !this$type.equals(other$type)) {
            return false;
        }
        AcceptController this$acceptController = this.getAcceptController();
        AcceptController other$acceptController = other.getAcceptController();
        if (this$acceptController == null ? other$acceptController != null : !(this$acceptController).equals(other$acceptController)) {
            return false;
        }
        IndexController this$indexController = this.getIndexController();
        IndexController other$indexController = other.getIndexController();
        if (this$indexController == null ? other$indexController != null : !(this$indexController).equals(other$indexController)) {
            return false;
        }
        Timer this$timer = this.getTimer();
        Timer other$timer = other.getTimer();
        return !(this$timer == null ? other$timer != null : !this$timer.equals(other$timer));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AddAcceptController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        result = result * 59 + this.getPageSize();
        result = result * 59 + this.getDefaultPageCount();
        ObservableList<DiaoboOutData> $observableTableList = this.getObservableTableList();
        result = result * 59 + ($observableTableList == null ? 43 : $observableTableList.hashCode());
        AnchorPane $anchorPane = this.getAnchorPane();
        result = result * 59 + ($anchorPane == null ? 43 : $anchorPane.hashCode());
        ScrollPane $scrollPane = this.getScrollPane();
        result = result * 59 + ($scrollPane == null ? 43 : $scrollPane.hashCode());
        VBox $vBox = this.getVBox();
        result = result * 59 + ($vBox == null ? 43 : $vBox.hashCode());
        Button $enterBtn = this.getEnterBtn();
        result = result * 59 + ($enterBtn == null ? 43 : $enterBtn.hashCode());
        TableView<DiaoboOutData> $tableView = this.getTableView();
        result = result * 59 + ($tableView == null ? 43 : $tableView.hashCode());
        TableColumn<DiaoboOutData, CheckBox> $checkBox = this.getCheckBox();
        result = result * 59 + ($checkBox == null ? 43 : $checkBox.hashCode());
        TableColumn<DiaoboOutData, String> $wmPsdh = this.getWmPsdh();
        result = result * 59 + ($wmPsdh == null ? 43 : $wmPsdh.hashCode());
        TableColumn<DiaoboOutData, String> $wmCjrq = this.getWmCjrq();
        result = result * 59 + ($wmCjrq == null ? 43 : $wmCjrq.hashCode());
        TableColumn<DiaoboOutData, String> $totalAmount = this.getTotalAmount();
        result = result * 59 + ($totalAmount == null ? 43 : $totalAmount.hashCode());
        TableColumn<DiaoboOutData, String> $totalQty = this.getTotalQty();
        result = result * 59 + ($totalQty == null ? 43 : $totalQty.hashCode());
        TableColumn<DiaoboOutData, String> $type = this.getType();
        result = result * 59 + ($type == null ? 43 : $type.hashCode());
        AcceptController $acceptController = this.getAcceptController();
        result = result * 59 + ($acceptController == null ? 43 : ($acceptController).hashCode());
        IndexController $indexController = this.getIndexController();
        result = result * 59 + ($indexController == null ? 43 : ($indexController).hashCode());
        Timer $timer = this.getTimer();
        result = result * 59 + ($timer == null ? 43 : $timer.hashCode());
        return result;
    }

    public String toString() {
        return "AddAcceptController(pageSize=" + this.getPageSize() + ", defaultPageCount=" + this.getDefaultPageCount() + ", observableTableList=" + this.getObservableTableList() + ", anchorPane=" + this.getAnchorPane() + ", scrollPane=" + this.getScrollPane() + ", vBox=" + this.getVBox() + ", enterBtn=" + this.getEnterBtn() + ", tableView=" + this.getTableView() + ", checkBox=" + this.getCheckBox() + ", wmPsdh=" + this.getWmPsdh() + ", wmCjrq=" + this.getWmCjrq() + ", totalAmount=" + this.getTotalAmount() + ", totalQty=" + this.getTotalQty() + ", type=" + this.getType() + ", acceptController=" + this.getAcceptController() + ", indexController=" + this.getIndexController() + ", timer=" + this.getTimer() + ")";
    }
}

